home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / PNL Libraries / MySystem7.p < prev    next >
Encoding:
Text File  |  1994-08-27  |  2.2 KB  |  89 lines  |  [TEXT/PJMM]

  1. unit MySystem7;
  2.  
  3. interface
  4.  
  5. {Note:  InitUtilities must be called prior to using functions marked * in this file }
  6. {            (It is normally called by InitMainLoop in MyMainLoop.unit) }
  7.  
  8.     function MyFindFolder (vrn: integer; folder: OSType; var ovrn: integer; var oDirID: longInt): OSErr; { * }
  9.     function MyInteractWithUser (idleproc: Ptr): OSErr; { * }
  10.     function CreateTemporaryFile (fs: FSSpec): OSErr;
  11.     procedure SegmentSystem7;
  12.  
  13. implementation
  14.  
  15.     uses
  16.         AppleTalk, Aliases, PPCToolBox, Processes, EPPC, Notification, AppleEvents, {}
  17.         MyUtils, MyUtilities, MyNotifier, Folders, MyFileSystemUtils;
  18.  
  19.     const
  20.         pref_folder = 'Preferences';
  21.  
  22. {$S System7}
  23.     procedure SegmentSystem7;
  24.     begin
  25.     end;
  26.  
  27. {$S System7}
  28.     function MyFindFolder (vrn: INTEGER; folder: OSType; var ovrn: INTEGER; var oDirID: LONGINT): OSErr;
  29.         var
  30.             oe: OSErr;
  31.             name: str255;
  32.             prefDirID: longInt;
  33.             pb: HParamBlockRec;
  34.             gv: longInt;
  35.     begin
  36.         oe := noErr;
  37.         if (Gestalt(gestaltFindFolderAttr, gv) <> noErr) | (not BTST(gv, gestaltFindFolderPresent)) | (FindFolder(vrn, folder, true, ovrn, odirID) <> noErr) then begin
  38.             oe := GetDirID(sysenv.sysVRefNum, ovrn, oDirID);
  39.             if (oe = noErr) and (folder = kPreferencesFolderType) then begin
  40.                 name := pref_folder;
  41.                 oe := DirCreate(ovrn, oDirID, name, prefDirID);
  42.                 if oe = noErr then
  43.                     oDirID := prefDirID
  44.                 else begin
  45.                     with pb do begin
  46.                         ioNamePtr := @name;
  47.                         ioVRefNum := ovrn;
  48.                         ioDirID := oDirID;
  49.                         ioFDirIndex := 0;
  50.                     end;
  51.                     oe := PBGetCatInfo(@pb, false);
  52.                     if oe = noErr then
  53.                         oDirID := pb.ioDirID;
  54.                 end;
  55.                 oe := noErr;
  56.             end;
  57.         end;
  58.         MyFindFolder := oe;
  59.     end;
  60.  
  61. {$S System7}
  62.     function MyInteractWithUser (idleproc: Ptr): OSErr;
  63.         var
  64.             oe: OSErr;
  65.     begin
  66.         if system7 then
  67.             oe := AEInteractWithUser(maxLongInt, nil, idleproc)
  68.         else begin
  69.             if in_foreground then
  70.                 MyInteractWithUser := noErr
  71.             else begin
  72.                 Notify(true, true, 128, 0, 0, 0, 0);
  73. { Should wait til we are in the foreground, but its too messy }
  74.             end;
  75.         end;
  76.     end;
  77.  
  78. {$S System7}
  79.     function CreateTemporaryFile (fs: FSSpec): OSErr;
  80.         var
  81.             oe: OSErr;
  82.     begin
  83.         oe := MyFindFolder(-1, kTemporaryFolderType, fs.vRefNum, fs.parID);
  84.         if oe = noErr then
  85.             oe := CreateUniqueFile(fs, 'trsh', 'trsh');
  86.         CreateTemporaryFile := oe;
  87.     end;
  88.  
  89. end.